package fr.bull.learn.thread.chat;

import java.lang.Thread.State;

import org.apache.log4j.Logger;


/**
 * Lancement des threads 
 * @author Rouviere-X
 *
 */
public class TestThread {
	private static Logger log = Logger.getLogger(TestThread.class);
	
    public static void main(String[] args) {    	
    	Chat m = new Chat();
        new Titou(m, "Question", new String[]{ "Hi", "How are you ?", "I am also doing fine!" });
        new Titou(m,"Answer",  new String[]{ "Hi", "I am good, what about you?", "Great!" });
        new Titou(m,"brouille",  new String[]{ "######", "######", "######" });
        int activeCount = Thread.activeCount();
		try {
			log.debug("Monitor sleep "+activeCount+ " active threads");
        	Thread.sleep(2000);
		} catch (InterruptedException e) {			
			log.error("Main interrupt",e);
		}
		log.debug("Monitor sleep "+activeCount);
        while ((activeCount = Thread.activeCount()) >1) {
	        Thread[] tarray = new Thread[activeCount];
			Thread.enumerate(tarray );
			for (Thread t : tarray){
				log.debug(t.getName() + " is "+t.getState());
				if (t.getState() == State.WAITING) {
					t.interrupt(); // it's wake-up thread but not finish it
				}
			}
        }
    }
}